import java.util.Random;

public class MathExerciseGenerator {
    public static void main(String[] args) {
        Random random = new Random();
        int totalQuestions = 50;

        System.out.println("50道100以内加减法口算习题：");
        System.out.println("----------------------------------------");

        for (int i = 0; i < totalQuestions; i++) {
            // 随机选择加法(0)或减法(1)
            int operation = random.nextInt(2);
            int num1, num2;

            if (operation == 0) {
                // 生成加法题，确保和不超过50
                num1 = random.nextInt(100);
                num2 = random.nextInt(100 - num1 + 1); // +1确保可能出现和为100的情况
                System.out.printf("第%d题：%d + %d = \n", (i + 1), num1, num2);
            } else {
                // 生成减法题，确保结果非负
                num1 = random.nextInt(100) + 1; // 至少为1，避免0-0的情况
                num2 = random.nextInt(num1 + 1);
                System.out.printf("第%d题：%d - %d = \n", (i + 1), num1, num2);
            }

            // 每10题换行分隔，方便查看
            if ((i + 1) % 10 == 0) {
                System.out.println();
            }
        }

        System.out.println("----------------------------------------");
        System.out.println("题目生成完毕！");
    }
}